#include <bits/stdc++.h>
using namespace std;

void benchmark(const string &name, const auto &func) {
  auto start = chrono::high_resolution_clock::now();
  func();
  auto end = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
  cout << format("{} execution time: {} ms\n", name, duration.count());
}
int main() {
  int V;
  int n;
  cin >> V >> n;
  vector<int> values(n);
  for (auto &v : values) cin >> v;

  benchmark("normal", [&]() {
    vector<int> dp(V + 1);
    dp[0] = 1;
    for (auto v : values) {
      for (int i = V; i >= v; i --) {
        dp[i] |= dp[i - v];
      }
    }
    for (int i = V; i >= 0; i --) {
      if (dp[i]) {
        cout << V - i << endl;
        break;
      }
    }
  });
  benchmark("bitset", [&]() {
    // 0 1   dp
    bitset<200001> dp;
    dp[0] = 1;
    for (auto v : values) {
      dp |= dp << v;
    }
    for (int i = V; i >= 0; i --) {
      if (dp[i]) {
        cout << V - i << endl;
        break;
      }
    }
  });
}
